//
//  ByCellCard.m
//  chequanbao_ios
//
//  Created by mc on 2017/5/9.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellCard.h"

// vc
#import "ByUIScanCodeVC.h"
#import "ByUIScanQRCodeVC.h"

@implementation ByCellCard

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellCard";
    ByCellCard *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}


-(void)createViews{

    CGFloat x,y,width,height;
    x = 35;
    y = 0;
    width = SCREEN_WIDTH - 2*x;
    height = 80;
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 4.0;
    [self addSubview:bgView];
    
    // 名片底部视图
    x = 30;
    y = 10;
    width = 40 + 20;
    height = 40 + 10 + 20;
    UIView *card_bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [bgView addSubview:card_bgView];
    
    x = 10;
    y = 0;
    width = height = 40;
    UIImageView *card_img = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    card_img.image = [UIImage imageNamed:@"card_mingpian"];
    [card_bgView addSubview:card_img];
    
    x = 0;
    y = card_img.bottom + 5;
    width = card_bgView.width;
    height = 15;
    UILabel *card_label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [card_bgView addSubview:card_label];
    card_label.text = @"名片";
    card_label.textAlignment = NSTextAlignmentCenter;
    card_label.textColor = BY_THEME_COLOR;
    card_label.font = FONT(14);
    
    //扫码
    y = 10;
    width = card_bgView.width;
    height = card_bgView.height;
    UIView *scan_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, y, width, height)];
    scan_bgView.right = bgView.right - 30 - 35;
    [bgView addSubview:scan_bgView];
    
    x = 10;
    y = 0;
    width = height = 40;
    UIImageView *scan_img = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    scan_img.image = [UIImage imageNamed:@"card_scan"];
    [scan_bgView addSubview:scan_img];
    
    x = 0;
    y = scan_img.bottom + 5;
    width = scan_bgView.width;
    height = 15;
    UILabel *scan_label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    scan_label.textAlignment = NSTextAlignmentCenter;
    [scan_bgView addSubview:scan_label];
    scan_label.font = FONT(14);
    scan_label.text = @"扫码";
    
    scan_bgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scanAction)];
    [scan_bgView addGestureRecognizer:tap];
}

// 扫描
- (void)scanAction{
    ByUIScanCodeVC *vc = [[ByUIScanCodeVC alloc] init];
//    ByUIScanQRCodeVC *vc = [[ByUIScanQRCodeVC alloc] init];
    [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];

}
@end
